package d8_stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

/**
 * 2024/6/7 Cjj Stream流提供的常见中间方法
 */
public class StreamTest3 {
    public static void main(String[] args) {
        List<Double> score = new ArrayList<>();
        Collections.addAll(score,88.5,100.0,60.0,99.0,9.5,99.6,25.0);

          List<Student> students = new ArrayList<>();
          Student s1= new Student("蜘蛛精",23,176.3);
          Student s2= new  Student("紫霞",26,187.4);
          Student s3 = new Student("紫霞", 15, 156.4);
          Student s4 = new Student("至尊宝", 22, 178.7);
          Collections.addAll(students,s1,s2,s3,s4);

          //1.找出成绩大于60分的数据,并升序后输出
        score.stream().filter(s ->s>=60).sorted().forEach(s->System.out.println(s));


         //2.找出年龄大于等于23,且年龄小于等于30岁的学生,并按照年龄降序输出
        students.stream()
                .filter(a ->a.getAge()>=23 && a.getAge()<=30)
                .sorted((o1, o2) -> o2.getAge()- o1.getAge())
                .forEach(a->System.out.println(a));
        System.out.println("-----------------------------");

        //3. 取出身高最高的前3名学生,并输出
            students.stream().sorted((o1,o2)->Double.compare(o2.getHeight(),o1.getHeight()))
                    .limit(3).forEach(s->System.out.println(s));
        System.out.println("-----------------------------");

        //4.取出身高倒数第2名的学生并输出
        students.stream().sorted((o1, o2) -> Double.compare(o2.getHeight(), o1.getHeight()))
                .skip(students.size()-2).forEach(System.out::println);
        System.out.println("-----------------------------");

        //5.找出身高超过168的学生叫什么名字,要求去除重复的名字,在输出
        students.stream().filter(s ->s.getHeight()>168).map(Student::getName)
                .distinct().forEach(System.out::println);

        Stream<Integer> stream = Stream.of(1, 2);
        Stream<Integer> stream1 = Stream.of(3, 4);
        Stream<Integer> concat = Stream.concat(stream, stream1);
        concat.forEach(System.out::println);
    }
}
